<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="业务时间:YYYY-MM-DD HH:MM:SS" prop="busitime">
      <el-input v-model="dataForm.busitime" placeholder="业务时间:YYYY-MM-DD HH:MM:SS"></el-input>
    </el-form-item>
    <el-form-item label="发起网点号" prop="obankid">
      <el-input v-model="dataForm.obankid" placeholder="发起网点号"></el-input>
    </el-form-item>
    <el-form-item label="登记中心机构号" prop="bankid">
      <el-input v-model="dataForm.bankid" placeholder="登记中心机构号"></el-input>
    </el-form-item>
    <el-form-item label="发起银行机构号" prop="bdcno">
      <el-input v-model="dataForm.bdcno" placeholder="发起银行机构号"></el-input>
    </el-form-item>
    <el-form-item label="业务标识码" prop="servicecode">
      <el-input v-model="dataForm.servicecode" placeholder="业务标识码"></el-input>
    </el-form-item>
    <el-form-item label="交易码" prop="msgtp">
      <el-input v-model="dataForm.msgtp" placeholder="交易码"></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="userid">
      <el-input v-model="dataForm.userid" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="用户真实姓名" prop="username">
      <el-input v-model="dataForm.username" placeholder="用户真实姓名"></el-input>
    </el-form-item>
    <el-form-item label="部门名称" prop="depart">
      <el-input v-model="dataForm.depart" placeholder="部门名称"></el-input>
    </el-form-item>
    <el-form-item label="业务操作信息" prop="content">
      <el-input v-model="dataForm.content" placeholder="业务操作信息"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          busitime: '',
          obankid: '',
          bankid: '',
          bdcno: '',
          servicecode: '',
          msgtp: '',
          userid: '',
          username: '',
          depart: '',
          content: '',
          remark: ''
        },
        dataRule: {
          busitime: [
            { required: true, message: '业务时间:YYYY-MM-DD HH:MM:SS不能为空', trigger: 'blur' }
          ],
          obankid: [
            { required: true, message: '发起网点号不能为空', trigger: 'blur' }
          ],
          bankid: [
            { required: true, message: '登记中心机构号不能为空', trigger: 'blur' }
          ],
          bdcno: [
            { required: true, message: '发起银行机构号不能为空', trigger: 'blur' }
          ],
          servicecode: [
            { required: true, message: '业务标识码不能为空', trigger: 'blur' }
          ],
          msgtp: [
            { required: true, message: '交易码不能为空', trigger: 'blur' }
          ],
          userid: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          username: [
            { required: true, message: '用户真实姓名不能为空', trigger: 'blur' }
          ],
          depart: [
            { required: true, message: '部门名称不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '业务操作信息不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcbusilog/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.busitime = data.bdcBusilog.busitime
                this.dataForm.obankid = data.bdcBusilog.obankid
                this.dataForm.bankid = data.bdcBusilog.bankid
                this.dataForm.bdcno = data.bdcBusilog.bdcno
                this.dataForm.servicecode = data.bdcBusilog.servicecode
                this.dataForm.msgtp = data.bdcBusilog.msgtp
                this.dataForm.userid = data.bdcBusilog.userid
                this.dataForm.username = data.bdcBusilog.username
                this.dataForm.depart = data.bdcBusilog.depart
                this.dataForm.content = data.bdcBusilog.content
                this.dataForm.remark = data.bdcBusilog.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcbusilog/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'busitime': this.dataForm.busitime,
                'obankid': this.dataForm.obankid,
                'bankid': this.dataForm.bankid,
                'bdcno': this.dataForm.bdcno,
                'servicecode': this.dataForm.servicecode,
                'msgtp': this.dataForm.msgtp,
                'userid': this.dataForm.userid,
                'username': this.dataForm.username,
                'depart': this.dataForm.depart,
                'content': this.dataForm.content,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
